package edu.washington.cs.sounddetector.server.api.object;

import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * SoundClass holds the name for a sound class and its associated color as an rgb integer.
 * 
 * @author the.dylan.price@gmail.com
 * 
 */
public class SoundClass
{
    private String soundClass;
    private int rgbColor;

    public SoundClass()
    {
    }

    /**
     * @param soundClass
     *            the class of the sound
     * @param rgbColor
     *            the color for the class
     */
    public SoundClass(String soundClass, int rgbColor)
    {
        Validate.notBlank(soundClass);
        this.soundClass = soundClass;
        this.rgbColor = rgbColor;
    }

    /**
     * @return the soundClass
     */
    public String getSoundClass()
    {
        return soundClass;
    }

    /**
     * @param soundClass
     *            the soundClass to set
     */
    public void setSoundClass(String soundClass)
    {
        this.soundClass = soundClass;
    }

    /**
     * @return the rgbColor, or -1 if no color has been set.
     */
    public int getRgbColor()
    {
        return rgbColor;
    }

    /**
     * @param rgbColor
     *            the rgbColor to set
     */
    public void setRgbColor(int rgbColor)
    {
        this.rgbColor = rgbColor;
    }

    public String toString()
    {
        return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
                .append("soundClass", soundClass).append("rgbColor", rgbColor).toString();
    }

    @Override
    public int hashCode()
    {
        return new HashCodeBuilder().append(soundClass).append(rgbColor).hashCode();
    }

    @Override
    public boolean equals(Object obj)
    {
        if (!(obj instanceof SoundClass))
        {
            return false;
        }
        SoundClass other = (SoundClass) obj;
        return new EqualsBuilder().append(this.soundClass, other.soundClass)
                .append(this.rgbColor, other.rgbColor).isEquals();
    }

}
